#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:zhuyan
@file: sync_queue.py
@time: 2018/08/23
"""

import threading, queue
import time, random


class SyncQueue(threading.Thread):

    def __init__(self,index,queue):
        threading.Thread.__init__(self)
        self.index = index
        self.queue = queue

    def run(self):
        while 1:
            time.sleep(random.random())
            item = self.queue.get()
            print("index:",self.index,"task",item,"finish")
            self.queue.task_done()


if __name__ == '__main__':
    q = queue.Queue(0)
    for i in range(2):
        s = SyncQueue(i, q)
        s.start()

    for i in range(10):
        q.put(i)
    for i in range(2):
        q.put(None)



